// Fill out your copyright notice in the Description page of Project Settings.

#include "ClientNet.h"
#include "NetPacket.h"
#include "CommonFunction.h"
#include <cstring.h>

NetPacket::NetPacket()
{
	mPacketID = -1;
	mBodyLen = -1;
	mBody = nullptr;
}

NetPacket::~NetPacket()
{
	SAFE_DELETE_ARRAY(mBody);
}

bool NetPacket::WriteBody(unsigned char *src, int16 len)
{
	if (src == nullptr)
	{
		return false;
	}

	if (mBody == nullptr)
	{
		mBody = new unsigned char[len];
	}
	else
	{
		SAFE_DELETE_ARRAY(mBody);
		mBody = new unsigned char[len];
	}

	memcpy(mBody, src, len);

	return true;
}
